package com.youku.plugins.topbarV4.view
{
   import flash.display.Sprite;
   import com.youku.interfaces.ISkinChangeCompent;
   import com.youku.baseUI.BasePlayerButton;
   import flash.events.MouseEvent;
   import com.youku.utils.ReportUtil;
   import com.youku.plugins.topbarV4.TopbarEvent;
   import com.youku.utils.AssetUtil;
   import flash.text.TextFormat;
   import com.youku.skin.YaheiFontManager;
   import com.youku.PlayerConfig;
   import com.youku.skin.PartenerSkinManager;
   
   public class SizeDefer extends Sprite implements ISkinChangeCompent
   {
      
      public function SizeDefer() {
         super();
         this._enable = true;
         this.initItems();
         this.attchEvents();
         this.updateLayout();
         PartenerSkinManager.push(this);
      }
      
      public static const BUTTON_50:String = "50";
      
      public static const BUTTON_75:String = "75";
      
      public static const BUTTON_100:String = "100";
      
      public static const BUTTON_FULL:String = "full";
      
      protected var _50Button:BasePlayerButton;
      
      protected var _75Button:BasePlayerButton;
      
      protected var _100Button:BasePlayerButton;
      
      protected var _fullButton:BasePlayerButton;
      
      protected var _enable:Boolean;
      
      protected var _currentType:String;
      
      protected var _span:Number = 10;
      
      private function initItems() : void {
         this._50Button = this.getButton();
         this._50Button.label = "50%";
         this._75Button = this.getButton();
         this._75Button.label = "75%";
         this._100Button = this.getButton();
         this._100Button.label = "100%";
         this._fullButton = this.getButton();
         this._fullButton.label = "满屏";
         addChild(this._50Button);
         addChild(this._75Button);
         addChild(this._100Button);
         addChild(this._fullButton);
      }
      
      private function attchEvents() : void {
         this._50Button.addEventListener(MouseEvent.CLICK,this.onButtonClick);
         this._75Button.addEventListener(MouseEvent.CLICK,this.onButtonClick);
         this._100Button.addEventListener(MouseEvent.CLICK,this.onButtonClick);
         this._fullButton.addEventListener(MouseEvent.CLICK,this.onButtonClick);
      }
      
      private function onButtonClick(param1:MouseEvent) : void {
         if(param1.currentTarget == this._50Button)
         {
            ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_50,ReportUtil.METHOD_LEFT_CLICK);
            this.selectButton(SizeDefer.BUTTON_50);
            dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_50_CLICK));
         }
         else if(param1.currentTarget == this._75Button)
         {
            ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_75,ReportUtil.METHOD_LEFT_CLICK);
            this.selectButton(SizeDefer.BUTTON_75);
            dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_75_CLICK));
         }
         else if(param1.currentTarget == this._100Button)
         {
            ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_100,ReportUtil.METHOD_LEFT_CLICK);
            this.selectButton(SizeDefer.BUTTON_100);
            dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_100_CLICK));
         }
         else if(param1.currentTarget == this._fullButton)
         {
            ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_FULLSCREEN,ReportUtil.METHOD_LEFT_CLICK);
            this.selectButton(SizeDefer.BUTTON_FULL);
            dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_FULL_CLICK));
         }
         
         
         
      }
      
      private function updateLayout() : void {
         this._50Button.x = 0;
         this._75Button.x = this._50Button.x + this._50Button.width + this._span;
         this._100Button.x = this._75Button.x + this._75Button.width + this._span;
         this._fullButton.x = this._100Button.x + this._100Button.width + this._span;
         this._50Button.y = this._75Button.y = this._100Button.y = this._fullButton.y = 4;
      }
      
      public function selectButton(param1:String) : void {
         if(!this._enable)
         {
            return;
         }
         this._50Button.enabled = true;
         this._75Button.enabled = true;
         this._100Button.enabled = true;
         this._fullButton.enabled = true;
         switch(param1)
         {
            case SizeDefer.BUTTON_50:
               this._50Button.enabled = false;
               this._currentType = SizeDefer.BUTTON_50;
               break;
            case SizeDefer.BUTTON_75:
               this._75Button.enabled = false;
               this._currentType = SizeDefer.BUTTON_75;
               break;
            case SizeDefer.BUTTON_100:
               this._100Button.enabled = false;
               this._currentType = SizeDefer.BUTTON_100;
               break;
            case SizeDefer.BUTTON_FULL:
               this._fullButton.enabled = false;
               this._currentType = SizeDefer.BUTTON_FULL;
               break;
         }
      }
      
      public function upgradeMode() : void {
         switch(this._currentType)
         {
            case SizeDefer.BUTTON_50:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_75,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_75);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_75_CLICK));
               break;
            case SizeDefer.BUTTON_75:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_100,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_100);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_100_CLICK));
               break;
            case SizeDefer.BUTTON_100:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_FULLSCREEN,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_FULL);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_FULL_CLICK));
               break;
            case SizeDefer.BUTTON_FULL:
               break;
         }
      }
      
      public function downgradeMode() : void {
         switch(this._currentType)
         {
            case SizeDefer.BUTTON_50:
               break;
            case SizeDefer.BUTTON_75:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_50,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_50);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_50_CLICK));
               break;
            case SizeDefer.BUTTON_100:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_75,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_75);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_75_CLICK));
               break;
            case SizeDefer.BUTTON_FULL:
               ReportUtil.sendUserActionLog(ReportUtil.FRAME_SCALE_100,ReportUtil.METHOD_MOUSE_WHEEL);
               this.selectButton(SizeDefer.BUTTON_100);
               dispatchEvent(new TopbarEvent(TopbarEvent.TOPBAR_100_CLICK));
               break;
         }
      }
      
      public function set enable(param1:Boolean) : void {
         this._enable = param1;
         if(this._enable)
         {
            this.visible = true;
            this.selectButton(this._currentType);
         }
         else
         {
            this.visible = false;
         }
      }
      
      public function getButton() : BasePlayerButton {
         var _loc1_:BasePlayerButton = AssetUtil.getStyleButton("T_btn");
         AssetUtil.restoreButtonSize(_loc1_);
         _loc1_.setStyle("textFormat",new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,10987431));
         _loc1_.setStyle("disabledTextFormat",new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,0));
         _loc1_.setStyle("textPadding",-3);
         _loc1_.hardOffset = -2;
         _loc1_.validateNow();
         return _loc1_;
      }
      
      public function upDateSkin() : void {
         if(PlayerConfig.rootData.styleid < 2)
         {
            return;
         }
         if(PlayerConfig.partnerData.skinData.status == 0 || !PlayerConfig.partnerData.skinData.isSetupDiv)
         {
            return;
         }
         this.changeButtonSkin(this._50Button);
         this.changeButtonSkin(this._75Button);
         this.changeButtonSkin(this._100Button);
         this.changeButtonSkin(this._fullButton);
      }
      
      public function clearSkin() : void {
         this.clearButtonSkin(this._50Button);
         this.clearButtonSkin(this._75Button);
         this.clearButtonSkin(this._100Button);
         this.clearButtonSkin(this._fullButton);
      }
      
      private function changeButtonSkin(param1:BasePlayerButton) : void {
         param1.getStyle("overSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN);
         param1.getStyle("downSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN);
         param1.getStyle("disabledSkin").filters = PartenerSkinManager.getFilters(PartenerSkinManager.SETUP_BTN);
         param1.setStyle("disabledTextFormat",new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,PlayerConfig.partnerData.skinData.setup_txt));
         param1.validateNow();
      }
      
      private function clearButtonSkin(param1:BasePlayerButton) : void {
         param1.getStyle("overSkin").filters = [];
         param1.getStyle("downSkin").filters = [];
         param1.getStyle("disabledSkin").filters = [];
         param1.setStyle("disabledTextFormat",new TextFormat(YaheiFontManager.MICROSOFT_YAHEI,14,0));
         param1.validateNow();
      }
   }
}
